/**
 * 
 */
package lu.med.praxiswahl.wahlumed.client.addressbook;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;

/**
 * @author PatrickPierre
 * 
 */
public class AddressBookCellRenderer implements TableCellRenderer {

	private AddressBookModel model;

	private Color grey = new Color(240, 240, 240);
	private Color blue = new Color(0, 0, 250);
	private Color white = new Color(255, 255, 255);
	private Font bold = new Font("Verdana", Font.BOLD, 11);

	public AddressBookCellRenderer(AddressBookModel model) {
		this.model = model;
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		final JLabel label = new JLabel();
		JTextArea area = new JTextArea();

		label.setOpaque(true);
		area.setOpaque(true);
		
		label.setFont(new Font("Verdana", Font.PLAIN, 11));

		if (column == 1) {

			area.setText("" + model.getValueAt(row, column));
			area.setLineWrap(true);

			if (isSelected) {
				area.setBackground(blue);
				area.setForeground(white);
				area.setFont(bold);
				area.setBorder(BorderFactory.createLineBorder(Color.GREEN));
			} else {
				area.setBackground(table.getBackground());
				area.setForeground(table.getForeground());
			}

			if (row % 2 == 0) {
				area.setForeground(table.getForeground());
				area.setBackground(table.getBackground());
				
			} else {
				
				area.setForeground(table.getForeground());
				area.setBackground(grey);
			}
			
			return area;
		}else{
			label.setText("<html>" + "" + model.getValueAt(row, column)
					+ "</html>");
			
			if (isSelected) {
				label.setBackground(blue);
				label.setForeground(white);
				label.setFont(bold);
				label.setBorder(BorderFactory.createLineBorder(Color.GREEN));
			} else {
				label.setBackground(table.getBackground());
				label.setForeground(table.getForeground());
			}
		}
		if (model == null) {
			label.setText("");
		} else {
			label.setText((String) model.getValueAt(row, column));
		}
		if (row % 2 == 0) {
			label.setForeground(table.getForeground());
			label.setBackground(table.getBackground());
			
		} else {
			
			label.setForeground(table.getForeground());
			label.setBackground(grey);

		}
		

		return label;
	}

}
